package com.lxl;

import java.util.Random;
import java.util.Scanner;

public class Example3 {
    public static void main(String[] args) {
        System.out.println("随机点名");
        String[] strings = new String[3];
        addStudentName(strings);
        printStudentName(strings);
        String s = randomStudentName(strings);
        System.out.println(s);
    }

    //添加一堆学生方法
    public static void addStudentName(String[] students) {
        Scanner scanner = new Scanner(System.in);

        for (int i = 0; i < students.length; i++) {
            System.out.println("存储第" + "i+1" + "个姓名:");
            students[i] = scanner.next();
        }
    }

    //打印一推学生方法
    public static void printStudentName(String[] students) {
        for (int i = 0; i < students.length; i++) {
            String name = students[i];
            System.out.println("第" + (i + 1) + "个同学的姓名:" + name);
        }
    }

    //生成随机学生姓名
    public static String randomStudentName(String[] students) {
        int i = new Random().nextInt(students.length);
        String name = students[i];
        return name;
    }

}
